package syg._01_activiti_businessKey;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;

/**
 * @author SYG
 */
public class _01_BusinessKey {

    /**
     * 添加业务id到流程表中,只能是在流程启动的时候,不能在流程部署,也不能在操作任务的时候
     *
     * 启动流程实例,添加业务id
     *
     * act_ru_task
     * act_ru_execution
     */
    @Test
    public void test1() {
        // 1、得到ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 2、获取RunTimeService(因为我们要启动流程,启动流程相关的service是RuntimeService)
        RuntimeService runtimeService = processEngine.getRuntimeService();
        // 3、启动流程实例,同时指定业务标识businessKey,业务表中id
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myEvection", "业务表id字段");
        // 4、从流程表中获取businessKey
        System.out.println("业务表id字段=" + processInstance.getBusinessKey());
    }
}
